/*
Copyright (c) 2007 Emmanuel Bonnet, blog.emmanuelbonnet.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

package wiiless.wiiless
{

	public class WiilessList
	{
		
		/**
		 * Tableau des Wiiless
		 */
		private var _aWiiless:Array;
		
		/**
		 * Constructeur
		 */
		function WiilessList()
		{
			_aWiiless = new Array();
		}
		
		/**
		 * Ajout d'une Wiiless
		 * 
		 * @param	pWiiless		Wiiless
		 */
		public function addWiiless(pWiiless:Wiiless):int
		{
			if(!isWiilessExist(pWiiless))
				_aWiiless.push(pWiiless);
			return _aWiiless.length;
		}
		
		/**
		 * Suppression d'une Wiiless
		 * 
		 * @param	pWiiless		Wiiless
		 */
		public function removeWiiless(pWiiless:Wiiless):int
		{
			var nWiiless:int = _aWiiless.length;
			for(var i:int=0; i<nWiiless; i++)
			{
				if(_aWiiless[i] == pWiiless)
				{
					_aWiiless.splice(i, 1);
					return _aWiiless.length;
				}
					
			}
			return _aWiiless.length;
		}
		
		/**
		 * Renvoi si la wiiless existe déja
		 * 
		 * @param	pWiiless		Wiiless
		 */
		public function isWiilessExist(pWiiless:Wiiless):Boolean
		{
			var nWiiless:int = _aWiiless.length;
			for(var i:int=0; i<nWiiless; i++)
			{
				if(_aWiiless[i] == pWiiless)
					return true;
			}
			return false;
		}
		
		/**
		 * Renvoi d'un wiiless en fonction de son id
		 * 
		 * @param	id		Id de la wiiless
		 */
		public function getWiilessById(pId:int):Wiiless
		{
			var nWiiless:int = _aWiiless.length;
			for(var i:int=0; i<nWiiless; i++)
			{
				if(_aWiiless[i].id == pId)
					return _aWiiless[i];
			}
			return null;
		}
		
		/**
		 * Suppresion d'une wiiless en fonction de son id
		 * 
		 * @param	id		Id de la wiiless
		 */
		public function removeWiilessById(pId:int):int
		{
			return removeWiiless(getWiilessById(pId));
		}
		
		/**
		 * Renvoi si la wiiless existe déja en fonction de son id
		 * 
		 * @param	id		Id de la wiiless
		 */
		public function isWiilessExistById(pId:int):Boolean
		{
			return isWiilessExist(getWiilessById(pId));
		}
		
		/**
		 * Renvoi le tableau des Wiiless
		 */
		public function getList():Array
		{
			return _aWiiless;
		}
		
		/**
		 * Reset la liste
		 */
		public function reset():void
		{
			_aWiiless = new Array();
		}
		
	}
}